import { _decorator, resources, SpriteFrame } from 'cc';
import Singleton from "../Base/Singleton";

export default class ResourceManager extends Singleton {
    static get Instance() {
        return super.GetInstance<ResourceManager>();
    }

    private constructor() {
        super();
    }

    loadDir(dir: string, type: typeof SpriteFrame = SpriteFrame) {
        return new Promise<SpriteFrame[]>((resolve, reject) => {
            resources.loadDir(dir, SpriteFrame, (err, data) => {
                if (err) {
                    console.error(err);
                    reject(err);
                } else {
                    resolve(data);
                }
            });
        });
    }
}